const utils = require('../../utils/util.js')
Component({
  properties: {
    detail: {
      type: Object,
      value: {}
    }
  },
  data: {
    currentSwiperIndex: 0,
    menuShow: false,
  },
  created(){
    console.log('rollcard data',this.data)
  },
  methods: {
    swiperChange(event) {
      if (event.detail.source === "touch") {
        this.setData({
          currentSwiperIndex: event.detail.current
        });
      }
    },
    swiperPrev() {
      this.setData({
        currentSwiperIndex: this.data.currentSwiperIndex - 1
      });
    },
    swiperNext() {
      this.setData({
        currentSwiperIndex: this.data.currentSwiperIndex + 1
      });
    },
    showMenu(){
      if (this.data.detail.createByMe ||  this.data.detail.state == '1'){
        this.setData({
          menuShow: true
        })
      }
    },
    hideMenu() {
      this.setData({
        menuShow: false
      })
    },
    editCard() {
      this.hideMenu();
      let url = '/pages/edit-card/edit-card?' + utils.serializeUrl(this.data.detail);
      wx.navigateTo({
        url
      })
    },
    saveToLocal() {
      this.hideMenu()
      console.log('保存到通讯录', this.data.detail)
      wx.addPhoneContact({
        firstName: this.data.detail.name,
        mobilePhoneNumber: this.data.detail.mobile,
        success(res) {
          console.log('保存名片成功', res)
        },
        fail(res) {
          console.log('保存名片失败', res)
        }
      })
    },
    deleteCard() {
      this.hideMenu()
      this.triggerEvent('deletemycard')
    },
    deleteHisCard(){
      this.hideMenu()
      this.triggerEvent('deletehiscard')
    }
  }
});
